'use strict';

App.controller('holidayController', ['$rootScope', '$scope', 'Page', function($rootScope, $scope, Page) {

    $scope.$on('$viewContentLoaded', function() {
        $scope.calendars.showYear($scope.year);
        $scope.selectDate($scope.year);
    });
    $scope.year = new Date().getFullYear();
    $scope.nextYear = function() {
        $scope.calendars.showYear(++$scope.year);
        $scope.selectDate();
	};
    $scope.prevYear = function() {
        $scope.calendars.showYear(--$scope.year);
        $scope.selectDate();
    };
    $scope.selectDate = function() {
        Page.ajaxGet('holiday/query.do', {startDate: $scope.year + '-01-01', endDate: $scope.year + '-12-31'}, function(resp) {
            var dates = [];
            $(resp.data).each(function(i, data) {
                dates.push(data.holidayDate.substr(0, 10));
            });
            // console.log(dates)
            $scope.calendars.select(dates);
        });
	};
    $scope.setWeekend = function() {
        $scope.calendars.selectWeekend();
	};
    $scope.save = function() {
        Page.ajaxPost('holiday/save.do', {year: $scope.year, dates: $scope.calendars.getSelected().join(',')}, function(resp) {
            Page.notice('保存成功！');
        });
	}

}]);